package com.lw.extraceim.ui.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

import com.lw.extraceim.R;
import com.lw.extraceim.ui.activity.base.BaseActivity;

public class FindPassActivity extends BaseActivity {
    private EditText mEditTextphone,mEditTextNewPass,mEditTextConfirm,mEditTextGetCode;
    private ImageView mImageViewError01,mImageViewError02,mImageViewError03;
    private Button mBtnSave,mBtnGetCode;
    private ImageButton mImageButton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_find_pass);
        mEditTextphone=findViewById(R.id.et_phone);
        mEditTextNewPass=findViewById(R.id.et_new_pass);
        mEditTextConfirm=findViewById(R.id.et_confirm);
        mEditTextGetCode=findViewById(R.id.et_get_security_code);
        mImageViewError01=findViewById(R.id.image_erro1);
        mImageViewError02=findViewById(R.id.image_erro2);
        mImageViewError03=findViewById(R.id.image_erro3);
        mBtnSave=findViewById(R.id.btn_save);
        mBtnGetCode=findViewById(R.id.btn_get_security_code);
        mImageButton=findViewById(R.id.imagebutton_back);
    }

    @Override
    public void initData() {

    }

    @Override
    public void refreshUI() {

    }

    @Override
    public void initEvent() {
        mEditTextphone.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if(!s.toString().matches("[0-9]+"))
                {
                    //输入并不是全是数字
                    mImageViewError01.setVisibility(View.VISIBLE);
                    Toast.makeText(getApplicationContext(),"不能含有非数字字符",Toast.LENGTH_SHORT).show();
                }
                if(s.toString().length()>11)
                {
                    mImageViewError01.setVisibility(View.VISIBLE);
                    Toast.makeText(getApplicationContext(),"不能超过11位",Toast.LENGTH_SHORT).show();
                }
                mImageViewError01.setVisibility(View.INVISIBLE);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        mEditTextConfirm.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                    String pass=mEditTextNewPass.getText().toString();
                    String confirm=mEditTextConfirm.getText().toString();
                    if(!pass.equals(confirm))
                    {
                        mImageViewError03.setVisibility(View.VISIBLE);
                    }
                    else
                        mImageViewError03.setVisibility(View.INVISIBLE);
            }
        });
        mImageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
